<template>
  <div class="detail" v-if="list.length > 0">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>户主信息</span>
      </div>
      <div>
        <el-row :gutter="20">
          <el-col :span="8"> <span>姓名</span>{{ list[0].name }} </el-col>
          <el-col :span="8">
            <span>性别</span>{{ sexMap[list[0].sex] }}
          </el-col>
          <el-col :span="8"> <span>民族</span>{{ list[0].nation }} </el-col>
          <el-col :span="8"> <span>手机号</span>{{ list[0].mobile }} </el-col>
          <el-col :span="8">
            <span>出生日期</span>{{ list[0].birthday }}
          </el-col>
          <el-col :span="8"> <span>身份证号</span>{{ list[0].idCard }} </el-col>
          <el-col :span="8">
            <span>籍贯</span>{{ list[0].nativePlace }}
          </el-col>
          <el-col :span="8"> <span>现住址</span>{{ list[0].address }} </el-col>
          <template v-if="list[0].personType != '0'">
            <el-col :span="8">
              <span>户籍状态</span
              ><span style="color: red;">{{
                personTypeMap[list[0].personType]
              }}</span>
            </el-col>
          </template>
          <template v-if="list[0].personType == '1'">
            <el-col :span="8">
              <span>迁出时间</span>{{ list[0].moveOut }}
            </el-col>
          </template>
          <template v-if="list[0].personType == '2'">
            <el-col :span="8">
              <span>迁入时间</span>{{ list[0].moveIn }}
            </el-col>
          </template>
          <el-col :span="24">
            <span>备注消息</span>{{ list[0].remark }}
          </el-col>
        </el-row>
      </div>
    </el-card>
    <el-card class="box-card" style="margin-top: 20px;">
      <div slot="header" class="clearfix">
        <span>家庭其他成员信息（{{ list.slice(1).length }}人）</span>
        <el-button
          type="success"
          icon="el-icon-plus"
          plain
          size="small"
          @click="goAdd()"
          >添加成员</el-button
        >
      </div>
      <template>
        <div class="item" v-for="(item, index) in list.slice(1)" :key="index">
          <el-row :gutter="20">
            <el-col
              :span="24"
              style="text-align:center; color:#409EFF; font-size: 12px;"
            >
              {{ index + 1 }}
            </el-col>
            <el-col :span="8"> <span>姓名</span>{{ item.name }} </el-col>
            <el-col :span="8"> <span>性别</span>{{ sexMap[item.sex] }} </el-col>
            <el-col :span="8"> <span>民族</span>{{ item.nation }} </el-col>
            <el-col :span="8">
              <span>与户主关系</span>{{ item.relation }}
            </el-col>
            <el-col :span="8"> <span>手机号</span>{{ item.mobile }} </el-col>
            <el-col :span="8">
              <span>出生日期</span>{{ item.birthday }}
            </el-col>
            <el-col :span="8"> <span>身份证号</span>{{ item.idCard }} </el-col>
            <el-col :span="8"> <span>籍贯</span>{{ item.nativePlace }} </el-col>
            <el-col :span="8"> <span>现住址</span>{{ item.address }} </el-col>
            <template v-if="item.personType != '0'">
              <el-col :span="8">
                <span>户籍状态</span
                ><span style="color: red;">{{
                  personTypeMap[item.personType]
                }}</span>
              </el-col>
            </template>
            <template v-if="item.personType == '1'">
              <el-col :span="8">
                <span>迁出时间</span>{{ item.moveOut }}
              </el-col>
            </template>
            <template v-if="item.personType == '2'">
              <el-col :span="8">
                <span>迁入时间</span>{{ item.moveIn }}
              </el-col>
            </template>
            <el-col :span="24"> <span>备注消息</span>{{ item.remark }} </el-col>
          </el-row>
        </div>
      </template>
    </el-card>
  </div>
</template>

<script>
import { storage } from "../../utils/storage";
export default {
  data() {
    return {
      houseId: this.$route.params.houseId,
      houseList: storage.getStorage("house"),
      personList: storage.getStorage("person"),
      list: [],
      sexMap: {
        "0": "男",
        "1": "女"
      },
      personTypeMap: {
        //户籍状态
        "0": "正常",
        "1": "已迁出",
        "2": "迁入"
      }
    };
  },
  methods: {
    getDetail() {
      var houesName = this.houseList.filter(
        item => item.houseId == this.houseId
      )[0].name;
      this.list = this.list
        .concat(
          this.personList.filter(
            item => item.houseId == this.houseId && item.name == houesName
          )
        )
        .concat(
          this.personList.filter(
            item => item.houseId == this.houseId && item.name != houesName
          )
        );
    },
    goAdd() {
      this.$router.push(`/person/add/${this.houseId}`);
    }
  },
  mounted() {
    this.getDetail();
  }
};
</script>

<style lang="scss" scoped>
.item {
  position: relative;
  margin-bottom: 50px;
  &:after {
    position: absolute;
    content: "";
    border: 1px dashed #dedede;
    width: 900px;
    left: 50%;
    margin-left: -450px;
    bottom: -25px;
  }
  &:last-child {
    margin-bottom: 0px;
    &:after {
      border: none;
    }
  }
}
</style>

